<template>
	<view class="content">
		<button class="size" @tap="getCamera">获取摄像头</button>
		<button class="size" @tap="captureImage">拍照</button>
		<button class="size" @tap="startVideoCapture">摄像</button>
		<button class="size" @tap="stopVideoCapture">停止摄像</button>
	</view>
</template>

<script>
	export default {
		data() {
			return {
				cmr:null
			}
		},
		onLoad() {
			
		},
		methods: {
			getCamera(){
				const cmr = plus.camera.getCamera();
				//属性
				// {
				// 	"__busy__": false,
				// 	"supportedImageResolutions": ["640*480", "1280*720", "960*540", "high", "medium", "low"],
				// 	"supportedVideoResolutions": ["640*480", "1280*720", "960*540"],
				// 	"supportedImageFormats": ["png", "jpg"],
				// 	"supportedVideoFormats": ["mp4"]
				// }
			},
			captureImage(){
				let cmr = plus.camera.getCamera();
				let res = cmr.supportedImageResolutions[0];
				let fmt = cmr.supportedImageFormats[0];
				console.log("res",res, "fmt",fmt);
				// 进行拍照操作的方法
				cmr.captureImage( function( path ){
						console.log( "Capture image success: " + path );  
					},
					function( error ) {
						console.log( "Capture image failed: " + error.message );
					},
					{resolution:res,format:fmt}
				);
			},
			startVideoCapture(){
					this.cmr = plus.camera.getCamera();
					let res = this.cmr.supportedVideoResolutions[0];
					let fmt = this.cmr.supportedVideoFormats[0];
					console.log("Resolution: "+res+", Format: "+fmt);
					this.cmr.startVideoCapture( function( path ){
							console.log( "Capture video success: " + path );  
						},
						function( error ) {
							console.log( "Capture video failed: " + error.message );
						},
						{resolution:res,format:fmt}
					);
			},
			stopVideoCapture(){
				this.cmr.stopVideoCapture();
			}
			
		}
	}
</script>

<style>
	.content {
		display: flex;
		flex-direction: column;
		align-items: center;
		justify-content: center;
	}

	.logo {
		height: 200rpx;
		width: 200rpx;
		margin-top: 200rpx;
		margin-left: auto;
		margin-right: auto;
		margin-bottom: 50rpx;
	}

	.text-area {
		display: flex;
		justify-content: center;
	}

	.title {
		font-size: 36rpx;
		color: #8f8f94;
	}
	.size{
		margin:30rpx 0;
	}
</style>
